package gov.nasa.anml.lifted;

import java.util.ArrayList;

import gov.nasa.anml.PDDL;
import gov.nasa.anml.State;
import gov.nasa.anml.utility.SimpleBoolean;
import gov.nasa.anml.utility.SimpleObject;

public abstract class CompoundIntervalExpression extends IntervalExpression<SimpleBoolean> {
	public ArrayList<IntervalExpression<SimpleBoolean>> expressions = new ArrayList<IntervalExpression<SimpleBoolean>>();
	
	public void add(IntervalExpression<SimpleBoolean> e) {
		expressions.add(e);
	}
	
	public void add(Expression<SimpleBoolean,?> e) {
		if (e instanceof IntervalExpression) {
			expressions.add((IntervalExpression<SimpleBoolean>)e);
		} else {
			TimeOfExpression f = new TimeOfExpression(e);
			expressions.add(f);
		}
	}
	
	public boolean apply(State p, int contextID, State c) {
		return value(p).v ? true : false;
	}
	
	public TypeCode typeCode() {
		return TypeCode.Boolean;
	}

	
	public PDDL.Expression translateExpr(PDDL pddl, Interval unit) {
		ArrayList<PDDL.BooleanExpression> a = new ArrayList<PDDL.BooleanExpression>();
		for (int i=0; i<this.expressions.size();++i) {
			IntervalExpression e = expressions.get(i);
			if (e.typeCode() != TypeCode.Boolean)
				continue;
			PDDL.BooleanExpression b = (PDDL.BooleanExpression) e.translateExpr(pddl,unit);
			a.add(b);
		}
		return pddl.wrap(PDDL.Op.and,a);
	}
	
	/*
	public SimpleBoolean value(State p) {
		for (int i=0;i<expressions.size();++i) {
			if (expressions.get(i).value(p) != ANMLBoolean.True)
				return ANMLBoolean.False;
		}
		return ANMLBoolean.True;
	}
	*/
	
	
}
